﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace XRoute.PathFinding.Test
{
    [TestClass]
    public class PriorityQueueTest
    {
        [TestMethod]
        public void TestQueueOrder()
        {
            var queue = new PriorityQueue<int, int>();

            queue.Enqueue(1, 101);
            queue.Enqueue(1, 100);

            queue.Enqueue(2, 200);
            queue.Enqueue(2, 201);

            queue.Enqueue(0, 0);
            queue.Enqueue(0, 1);

            Assert.AreEqual(0, queue.Dequeue());
            Assert.AreEqual(1, queue.Dequeue());
            Assert.AreEqual(101, queue.Dequeue());
            Assert.AreEqual(100, queue.Dequeue());
            Assert.AreEqual(200, queue.Dequeue());
            Assert.AreEqual(201, queue.Dequeue());
        }

        [TestMethod]
        public void TestEnqueueDequeue()
        {
            var queue = new PriorityQueue<int, int>();

            Assert.IsTrue(queue.IsEmpty);
            queue.Enqueue(1, 1);
            Assert.IsFalse(queue.IsEmpty);
            Assert.AreEqual(queue.Dequeue(), 1);
            Assert.IsTrue(queue.IsEmpty);
        }

        [TestMethod]
        [ExpectedException(typeof(InvalidOperationException))]
        public void TestDequeueThrows()
        {
            var queue = new PriorityQueue<int, int>();

            queue.Dequeue();
        }
    }
}
